package com.cti.commons.delayqueue.binding;

import java.lang.reflect.Method;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;
import org.springframework.web.method.support.HandlerMethodArgumentResolverComposite;
import org.springframework.web.method.support.InvocableHandlerMethod;

import com.cti.commons.delayqueue.handler.DelayMessageHandlerMethodFactory;

/**
 * @author et.wang
 * @description: 生成可执行的方法
 * @date 2022/11/21 11:25
 */
@Service
public class DelayMessageHandlerMethodFactoryImpl implements DelayMessageHandlerMethodFactory, BeanFactoryAware,
    InitializingBean {

    @Nullable
    private BeanFactory beanFactory;

    private final HandlerMethodArgumentResolverComposite argumentResolvers =
        new HandlerMethodArgumentResolverComposite();

    @Override
    public InvocableHandlerMethod createInvocableHandlerMethod(Object bean, Method method) {
        InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(bean, method);
        handlerMethod.setHandlerMethodArgumentResolvers(this.argumentResolvers);
        return handlerMethod;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }

}
